package cn.fl.ass.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.ass.service.IAssTrailCarDInfService;
import cn.fl.ass.transform.AssTrailCarDInfVOTransform;
import cn.fl.ass.vo.AssTrailCarDInfVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import fl.ass.facade.api.IAssTrailCarApi;
import fl.ass.facade.condition.AssTrailCarDInfQueryCondition;
import fl.ass.facade.dto.AssTrailCarDInfDTO;
import fl.ass.facade.dto.MessageDTO;

/**
 * @Description: 拖车实际信息明细表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AssTrailCarDInfServiceImpl implements IAssTrailCarDInfService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IAssTrailCarDInfService.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IAssTrailCarApi assTrailCarApi;

	@Override
	public AssTrailCarDInfVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			return null;
		}
		//查询拖车实际明细信息
		MessageDTO<AssTrailCarDInfDTO> response = this.assTrailCarApi.findAssTrailCarDInfById(id);
		return AssTrailCarDInfVOTransform.toVO(response.getData());
	}

	@Override
	public Long add(AssTrailCarDInfVO entity) throws BaseException{
		if(null == entity){
			return null;
		}
		//返回新增ID值-JL-20170328
		MessageDTO<String> response = this.assTrailCarApi.saveAssTrailCarDInf(AssTrailCarDInfVOTransform.toDTO(entity));
		return response.getId();
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			return false;
		}
		//return this.assTrailCarDInfApiService.removeById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(AssTrailCarDInfVO entity) throws BaseException{
		if(null == entity){
			return false;
		}
		//返回逻辑值-JL-20170315
		MessageDTO<String> response = this.assTrailCarApi.modifyTrailCarDInf(AssTrailCarDInfVOTransform.toDTO(entity));
		return response.isSuccess();
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.assTrailCarDInfApiService.searchListPage(page);
		//TODO 业务逻辑
		return null;
	}
	
	/**
	 * 根据支付表ID查询财务核算保底价金额信息
	 * @param paySchIds
	 * @return 对象DTO
	 */
	@Override
	public List<AssTrailCarDInfVO> selectMoneyByPaySchId(List<Long> paySchIds) throws BaseException{
		if(CollectionUtils.isEmpty(paySchIds)){
			return null;
		}
		//根据支付表ID查询财务核算保底价金额信息
		MessageDTO<AssTrailCarDInfDTO> dtoList = this.assTrailCarApi.findPayInfoListByPaySchIds(paySchIds);
		List<AssTrailCarDInfVO> voList = new ArrayList<AssTrailCarDInfVO>();
		//dtoList转voList
		if(null != dtoList.getDatas()){
			for (AssTrailCarDInfDTO dto : dtoList.getDatas()) {
				voList.add(AssTrailCarDInfVOTransform.toVO(dto));
			}
		}
		return voList;
	}

	@Override
	public AssTrailCarDInfVO selectPNoPaySchNoByDataId(Long dataId) throws BaseException {
		if(StringUtils.isEmpty(dataId)){
			return null;
		}
		//根据业务主键查询流程号和支付表号
		MessageDTO<AssTrailCarDInfDTO> response = this.assTrailCarApi.selectPNoPaySchNoByDataId(dataId);
		return AssTrailCarDInfVOTransform.toVO(response.getData());
	}

	@Override
	public List<AssTrailCarDInfVO> searchAssTrailCarDInfList(AssTrailCarDInfQueryCondition condition) throws BaseException {
		if(null == condition.getDetailId() && null == condition.getDetailIds()){
			return null;
		}
		MessageDTO<AssTrailCarDInfDTO> dtoList = this.assTrailCarApi.searchAssTrailCarDInfList(condition);
		List<AssTrailCarDInfVO> voList = new ArrayList<AssTrailCarDInfVO>();
		//dtoList转voList
		if(null != dtoList.getDatas()){
			for (AssTrailCarDInfDTO dto : dtoList.getDatas()) {
				voList.add(AssTrailCarDInfVOTransform.toVO(dto));
			}
		}
		return voList;
	}
}
